package com.ssm.xml.controller;

import com.ssm.xml.entity.SysUser;
import com.ssm.xml.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: Hsiao
 * @date: 2023-11-21
 * @description:
 */
@Controller
@RequestMapping("/api/users")
public class UserController {
    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/all")
    public String listAll(Model model){
        List<SysUser> users = userService.listAll();
        model.addAttribute("users",users);
        return "users";
    }

    @GetMapping("/list")
    @ResponseBody
    public  List<SysUser> list(){
        return userService.listAll();
    }
}
